<?php
error_reporting(0);
session_start();
include_once '../comm/config.php';
include_once '../comm/checkpostandget.php';
include_once 'check.php';
include_once 'page.class.php';
include_once '../comm/wjt.php';
include '../data/expression.php';

$shai_set=include '../data/shai.php';
$shaicat_arr=$shai_set['shai_cat'];
$shai_arr=array(0=>'<b class="shai" style="cursor:pointer; font-weight:normal">晒单</b>',1=>'<b style=" color:#5DDC4A; font-weight:normal">已晒单</b>');
$keyword=$_GET["keyword"]; 
$act=$_GET['act'];
$page = !($_GET['page'])?'1':intval($_GET['page']);
$pagesize=10;
$page2=($page-1)*$pagesize;

if (!$act) {
	echo "缺少必要参数";
	exit;
}
else
{
	if($act=='taobao'){
		$sql="SELECT a.Id, a.item_title, a.num_iid,a.pay_price, a.real_pay_fee,a.fxje, a.commission,a.trade_id,a.pay_time, b.id as shai_id FROM ".$BIAOTOU."tradelist AS a LEFT JOIN (".$BIAOTOU."shai AS b) ON ( a.Id = b.trade_id ) where a.outer_code='".$_SESSION["dduserid"]."' and a.trade_id like '%".$keyword."%' and a.checked=2";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		$sql="SELECT a.Id, a.item_title, a.num_iid,a.pay_price, a.real_pay_fee,a.fxje, a.commission,a.trade_id,a.pay_time, b.id as shai_id FROM ".$BIAOTOU."tradelist AS a LEFT JOIN (".$BIAOTOU."shai AS b) ON ( a.Id = b.trade_id ) where a.outer_code='".$_SESSION["dduserid"]."' and a.trade_id like '%".$keyword."%' and a.checked=2 order by a.pay_time desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
	
	if($act=='mall'){
		$sql="select * from ".$BIAOTOU."mall_order where u_id='".$_SESSION["dduserid"]."'";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		$sql="select * from ".$BIAOTOU."mall_order where u_id='".$_SESSION["dduserid"]."' order by id desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
	
	if($act=='lost'){
		if(!is_numeric($keyword)) $keyword='';
		$sql="select * from ".$BIAOTOU."tradelist where  (trade_id like '".$keyword."') and (outer_code='' or outer_code is NULL)";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		$sql="select Id, item_title, num_iid, real_pay_fee,fxje, commission,trade_id,pay_time from ".$BIAOTOU."tradelist where (trade_id like '".$keyword."') and  (outer_code='' or outer_code is NULL) order by pay_time desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
	
	if($act=='malllost'){
		if(strpos($keyword,'%')!==false || strpos($keyword,'_')!==false){
		    $keyword='%';
		}
		$sql="select * from ".$BIAOTOU."mall_order where  order_code like '".$keyword."' and (u_id='' or u_id is NULL)";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		$sql="select * from ".$BIAOTOU."mall_order where order_code like '".$keyword."' and  (u_id='' or u_id is NULL) order by order_time desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
	if($act=='checked'){
		$sql="select * from ".$BIAOTOU."tradelist where outer_code='".$_SESSION["dduserid"]."' and outer_code<>'' and checked=1";
		$rs = mysql_query($sql);
		$total = mysql_num_rows($rs);	
		$sql="select * from ".$BIAOTOU."tradelist where outer_code='".$_SESSION["dduserid"]."' and outer_code<>'' and checked=1 order by pay_time desc limit $page2,$pagesize";
		$rs = mysql_query($sql);
	}
}

$tag="center";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>订单管理 - 用户中心</title>

<link href="../template/<?=MOBAN?>/css/style.css" rel="stylesheet" type="text/css" />
<link  href="../template/<?=MOBAN?>/css/layout.css" rel="stylesheet" type="text/css" />
<link  href="../template/<?=MOBAN?>/css/comm.css" rel="stylesheet" type="text/css" />
<link href="../css/redirect.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.layout_body table td{border-bottom:#f1f1f1 solid 1px}
</style>

<script type="text/javascript" src="../js/jquery.js"></script>

<script>
commentDefaultVal='说说你对这件宝贝的评价吧';
msgErr=new Array();
msgErr[8]='评论不能为空或者含有敏感词';
msgErr[9]='必须添加图片';
msgErr[5]='不可重复晒单';
msgErr[1]='标签最多添加5个';
msgErr[4]='插入数据库失败';
msgErr[15]='此商品已有人分享过，换换别的吧，O(∩_∩)O';

function OnClick(id)
{
  for(i=1;i<=10;i++)
  {
	  document.getElementById("b_"+i).className="bshop1";
  }	
  document.getElementById("b_"+id).className="bshop2";
  var typeid=document.getElementById("b_"+id).name;
  document.getElementById("shopid").value=typeid;
}

function shsend(type)
{
	if(type==1) //显示
	{
		document.getElementById("send1").style.display="block";
		document.getElementById("send2").style.display="block";
		document.getElementById("shop1").style.display="none";
		document.getElementById("shop2").style.display="none";
		document.getElementById("jt1").style.display="none";
	}
	if(type==2) //隐藏
	{
		document.getElementById("send1").style.display="none";
		document.getElementById("send2").style.display="none";
		document.getElementById("shop1").style.display="block";
		document.getElementById("shop2").style.display="block";
		document.getElementById("jt1").style.display="block";	
	}
}

function addExpression(myField, myValue)
{
    myField = document.getElementById(myField);
	if(myField.value==commentDefaultVal) myField.value='';
    //IE
    if (document.selection)
    {
        myField.focus();
        sel = document.selection.createRange();
        myValue = myValue;
        sel.text = myValue;
        sel.select();
    }
    //MOZILLA
    else if (myField.selectionStart || myField.selectionStart == '0')
    {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        // save scrollTop before insert
        var restoreTop = myField.scrollTop;
        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos,myField.value.length);
        if (restoreTop > 0)
        {
            // restore previous scrollTop
            myField.scrollTop = restoreTop;
        }
        myField.focus();
        myField.selectionStart = startPos + myValue.length;
        myField.selectionEnd = startPos + myValue.length;
    }
    else
    {
        myField.value += myValue;
        myField.focus();
    }
}

$.ajaxSetup ({
    cache: false //关闭AJAX相应的缓存
});
$(function(){
    $('.close').click(function(){
	    $('.LightBox').hide();
		$('#jumpbox2').hide();
	});
	$('#taobao .shai').click(function(){
		$("input[name='shaicat'][type='radio']:checked").attr('checked','');
		//$('#keywords').val('');
		$('#tao_img').val('');
		$('#J_ImgBooth').attr('src','../images/wait.gif');
		$('#dopic').hide();
		$('#expression').fadeOut();
		trade_id = $(this).parents('div').attr('trade_id');
		title = $(this).parents('div').attr('title');
		price = $(this).parents('div').attr('price');
		fxje = $(this).parents('div').attr('fxje');
		num_iid = $(this).parents('div').attr('num_iid');

		object=$(this);
		$('#shopname').html(title);
		$('#shopprice b').html(price);
		$('#shopfx b').html(fxje);
		//$('#tao_url').val('http://item.taobao.com/item.htm?id='+num_iid);
		var url='http://item.taobao.com/item.htm?id='+num_iid;
		$('#comment').val(commentDefaultVal);
	    $('.LightBox').show();
		$('#jumpbox2').show();
		$.post("../a.php",{fun:'get_tao_img',url:url,xs:'shai'},function(data){//alert(data);
			var data= eval("(" + data + ")");
            if(data.img==null || data.img=='' || data.img=='_310x310.jpg'){
				alert('此商品已下架！');
				$('#J_ImgBooth').attr('src','../images/crying.gif');
				$('#subShare').attr('disabled','disabled');
			}
			else{
				clickUrl=data.clickUrl;
			    $('#J_ImgBooth').attr('src',data.img);
				$('#radio'+data.cid).attr("checked",true);
				$('#subShare').attr('disabled','');
			}
		});
	});
	$('#get_tao_img').click(function(){
	    var url=$('#tao_url').val();
		var f=$(this).attr('f');
		if(url==''){
		    alert('不能为空');
			$(this).focus();
		}
		else{
			if(f=='html'){
			    $.post("../a.php",{fun:'get_tao_img',url:url},function(data){
			        $('#J_ImgBooth').attr('src',data);
					$('#dopic').hide('normal');
			    });
			}
			else if(f=='jpg'){
				data=$('#tao_url').val();
			    $('#J_ImgBooth').attr('src',data);
				$('#dopic').hide('normal');
			} 
		}
	});
	$('#shaiForm').submit(function(){
        var tao_id=num_iid;
		var tao_img=$('#J_ImgBooth').attr('src');
		var keywords=$('#keywords').val();
		var comment=jQuery.trim($('#comment').val());
		var catid = $("input[name='shaicat'][type='radio']:checked").val();
        var l=keywords.split(/\s+/).length;
		var num=parseInt($('#num').text());
		//temp = comment.replace(/{.*?}/gim,""); //过滤表情字符
		if(tao_img=='' || tao_img=='../images/wait.gif' || tao_img=='null'  || tao_img=='_310x310.jpg'  || tao_img=='../images/crying.gif' ){
		    alert('商品已下架！');
			/*$('#jiantou').css('left','178px');
		    $('#tishi').html('添加图片远程地址');
			$('#dopic #get_tao_img').attr('f','jpg');
		    $('#dopic').show('normal');*/
		}
		else if(typeof catid=='undefined'){
		    alert('选择分类');
		}
		/*else if(temp==''){
		    alert('说点什么吧，不要只发表情哦');
		}*/
		else if(num<0){
		    alert('内容超限！');
			$('#comment').focus();
		}
		else if(comment=='' || comment==commentDefaultVal){
		    alert('请添加评论内容！');
			$('#comment').focus();
		}
		else if(l>5){
		    alert('最多填写5个关键词');
			$('#keywords').focus();
		}
		else{
			$('#subShare').attr('disabled','disabled');
		    $.post("../a.php",{fun:'save_shai',tao_id:tao_id,trade_id:trade_id,title:title,price:price,fxje:fxje,image:tao_img,keywords:keywords,catid:catid,comment:comment,xs:'shai','click_url':clickUrl},function(data){//$('#keywords').val(data);
				var data= eval("(" + data + ")");
				if(data.err==0){
				    alert('提交成功');
			        $('.LightBox').hide();
		            $('#jumpbox2').hide();
					$(object).removeClass();
					$(object).css('color','#5DDC4A');
					$(object).text('已晒单');
					$('#subShare').attr('disabled','');
				}
				else if(data.err==1){
					alert(msgErr[data.msg]);
					$('#subShare').attr('disabled','');
				}
		    });
		}
		return false;
	});
	$('#comment').bind('focus keyup input paste',function(){  //采用几个事件来触发（已增加鼠标粘贴事件）   
	     $('#num').text(80-$(this).attr("value").length)  //获取评论框字符长度并添加到ID="num"元素上  
	});
	$('.picfunc a:not(#openem)').click(function(){
	    var left=$(this).attr('left');
		var tishi=$(this).attr('val');
		var f=$(this).attr('f');
		if(f=='jpg'){$('#tao_url').val('');}
		$('#jiantou').css('left',left);
		$('#tishi').html(tishi);
		$('#dopic').show('normal');
		$('#get_tao_img').attr('f',f);
	});
})
</script>
<script>
function checkTradelist(){
    var keyword=document.getElementById('keyword').value;
	if(keyword=='输入订单号' || keyword==''){
	    alert('订单号不能为空');
		return false;
	}
}
</script> 
</head>

<?php
$modtag="center";
include("../template/".MOBAN."/header_user.tpl.php");
?>


<div class='layout_body'>

  <div class="uInfoTop">
     <div class="break"><a href="javascript:void();" onclick="javascript:window.history.back();"><img src="../template/<?=MOBAN?>/images/back.gif" width="29" height="30" border="0" /></a></div>
     <div class="username usernamefont"><?=$_SESSION["duoduouser"]?></div>
     <div class="userstate"><a class="ustatefont" href="exit.php">退出</a></div>
  </div>
  <div class="usertopline"></div>

  <div class="clears"></div>
  <div class="CreatL">
    <ul>
      <li class="UserSel"><a href="tradelist.php?act=taobao">返米管理</a></li>
      <li><a href="tuiguang_url.php"> 我要推广赚米</a></li>
      <li><a href="baobei.php">我的晒吧</a></li>
      <li><a href="huan.php">我的兑换</a></li>
    </ul>
  </div>

  <div class="CreatR">
    <ul class="babydetail MarginB10">
      <li <?php if($act=='taobao') echo "class=\"active\"";?>><a href="tradelist.php?act=taobao">淘宝返米记录</a></li>
      <li <?php if($act=='mall') echo "class=\"active\"";?>><a href="tradelist.php?act=mall">网店返米记录</a></li>
      <!--<li <?php if($act=='checked') echo "class=\"active\"";?>><a href="tradelist.php?act=checked">等待审核(淘宝)</a></li>-->
    </ul>
    <div class="clears"></div>
    <div class=" clears"></div>
    
    <div align="right" style="float:left;width:802px">
		<?php if($act=='taobao'){?>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
          <td width="22%" height="35" align="left" bgcolor="#f5f5f5">订单号</td>
          <td width="35%" align="left" bgcolor="#f5f5f5">宝贝名称</td>
          <td width="10%" align="left" bgcolor="#f5f5f5">价格/元</td>
          <td width="10%" align="left" bgcolor="#f5f5f5">返米</td>
          <td width="15%" align="left" bgcolor="#f5f5f5">成交时间</td>
          <td width="8%" align="left" bgcolor="#f5f5f5">操作</td>
        </tr>
        <?php while ($row = mysql_fetch_array($rs)){?>
        <tr>
          <td  width="22%" height="40" align="left"><?=$row["trade_id"]?></td>
          <td width="35%" align="left" style="text-align:left;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-right:30px"><?=$row["item_title"]?></td>
          <td width="10%" align="left"><font style="color:#F00"><?=($row["real_pay_fee"]>0?$row["real_pay_fee"]:$row['pay_price'])?></font></td>
          <td width="10%" align="left"><font style="color:#F00"><b><?=$row["fxje"]*100?></b></font></td>
          <td width="15%" align="left"><?=date("Y-m-d",strtotime($row["pay_time"]))?></td>
          <?php if($row["pay_time"]>=$shai_set['shai_s_time'])
          {
              echo "<td id=\"taobao\" width=\"8%\" align=\"left\"><div price='".$row["pay_price"]."' fxje='".($row["fxje"]*100)."' num_iid='".$row["num_iid"]."' title='".$row["item_title"]."' trade_id='".$row["Id"]."' class=\"item\" style=\"width:40px;text-align:center;color:#F00\">".$shai_arr[$row["shai_id"]?1:0]."</div></td>";
          }
          else
          {
            echo "<td width=\"8%\" align=\"left\">——</td>";  
          }?>
        </tr>
        <?php }}?>
        </table>
       
        <?php if($act=='mall'){?>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" >
          <tr>
          <td width="14%" height="35" align="left" bgcolor="#f5f5f5">订货号</td>
          <td width="14%" align="left" bgcolor="#f5f5f5">下单商城</td>
          <td width="14%" align="left" bgcolor="#f5f5f5">成交数量</td>
          <td width="14%" align="left" bgcolor="#f5f5f5">价格/元</td>
          <td width="14%" align="left" bgcolor="#f5f5f5">返米</td>
          <td width="14%" align="left" bgcolor="#f5f5f5">成交时间</td>
          <td width="14%" align="left" bgcolor="#f5f5f5">交易状态</td>
        </tr>
        <?php while ($row = mysql_fetch_array($rs)){?>
        <tr>
          <td width="14%" height="40" align="left"><?=$row["order_code"]?></td>
          <td width="14%" align="left"><?=$row["merchant_id"]?>1</td>
          <td width="14%" align="left"><?=$row["item_count"]?></td>
          <td width="14%" align="left"><font style="color:#F00"><?=$row["item_price"]?></font></td>
          <td width="14%" align="left"><font style="color:#F00"><b><?=round($row["fxje"],2)*100?></b></font></td>
          <td width="14%" align="left"><?=date("Y-m-d",strtotime($row["order_time"]))?></td>
          <td width="14%" align="left"><?=$row["stat_desc"]?></td>
        </tr>
        <?php }}?>
        </table>
      
        <?php if($act=='checked'){?>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
          <td width="20%" height="35" align="left" bgcolor="#f5f5f5">订单号</td>
          <td width="50%" align="left" bgcolor="#f5f5f5">宝贝名称</td>
          <td width="10%" align="left" bgcolor="#f5f5f5">价格/元</td>
          <td width="10%" align="left" bgcolor="#f5f5f5">返米</td>
          <td width="20%" align="left" bgcolor="#f5f5f5">成交时间</td>
        </tr>
        <?php while ($row = mysql_fetch_array($rs)){?>
        <tr>
          <td width="14%" height="24" align="left"><?=$row["trade_id"]?></td>
          <td width="14%" align="left"><?=$row["item_title"]?></td>
          <td width="14%" align="left"><?=($row["real_pay_fee"]>0?$row["real_pay_fee"]:$row['pay_price'])?></td>
          <td width="14%" align="left"><?=round($row["fxje"],2)*100?></td>
          <td width="14%" align="left"><?=date("Y-m-d",strtotime($row["pay_time"]))?></td>
        </tr>
        <?php }}?>
       </table>
       <div class="megas512" style="clear:both"><?php pageft($total,$pagesize,1,1,0,10,"mingxilist.php?act=".$act."");	echo $pagenav;?></div>  
    </div>
  </div>
</div>

<!--分享的浮动层--> 
<div class="fxframe" id="jumpbox2">
<div class="close"></div>
  <div class="fmbox">
   <div class="SelType">
    <ul>
        <?php foreach($shaicat_arr as $k=>$v){?>
        <li style="color:#FFF;width:50px"><input name="shaicat" value="<?=$k?>" type="radio" id="radio<?=$k?>"> <label for="radio<?=$k?>"><?=$v?></label></li>
        <?php }?>
        <input name="shaicat" type="hidden" id="shopid" value="" />
    </ul>
   </div>
   <div class="Enter">
      <!--<div class="jt" id="jt1"></div>
      <form>
       <div class="Editfm" id="shop1"><textarea id="tao_url" class="text" >在这里张贴宝贝的地址</textarea></div>
       <div class="bfm" id="shop2"> <input  f='html' id="get_tao_img" type="button" class="bnt" onclick="shsend(1)"  value="确 定" /></div>
     </form>-->
     <form id="shaiForm">
     <div class="Editfm" id="send1"><textarea id="comment" onfocus="if(this.value==commentDefaultVal){this.value=''};" class="text" ><?php if($buyid==0){?>您的等级不足，不能分享宝贝！<?php }else{?>说说你对这件宝贝的评价吧<?php }?></textarea></div>
     <div class="bfm" id="send2"> <input id="subShare" type="submit" class="bnt"  value="发 布" <?php if($buyid==0){?> disabled="disabled"<?php }?>/></div>
     <div class="line">
       <a onclick="$('#expression1').fadeIn('slow');"  id="openem" class="bp"></a><!--<a class="tb">--></a>
       <div class="rtxt" style="margin-right:80px">还可以输入<b id="num" style="font-size:14px; color:#FFF">80</b>个字</div>
     </div> 
       <input type="hidden" value="" id="trade_id" />
       <input type="hidden" value="" id="tao_img" /> 
     </form>  
   </div>
   <div class="shopInfo" id="shopinfo">
      <div class="shopic"><img id="J_ImgBooth" src="<?=$navheadurl?>images/no_news.gif" width="119" height="119" /></div>
      <div class="t" style="font-size:12px;margin-left:1px" id="shopname"></div>
      <div class="t" style="width:150px;margin-left:1px" id="shopprice">价格：<b style="font-size:14px;color:#FFF"></b>元</div>
      <div class="t" style="width:150px;margin-left:1px" id="shopfx">返米：<b style="font-size:14px;color:#FFF"></b>米</div>
      <div class="t" style="margin-left:1px">标签：<input id="keywords" type="text" style=" width:316px; height:29px; border:1px solid #d2caca; line-height:29px;color:#c7c3c3" value="填写商品关键字，用空格隔开"  /></div>
   </div>
  </div>
  
  <!--表情层-->
  <div class="emfm" id="expression1">
   <div class="top"><img src="../template/<?=MOBAN?>//images/bqjt.gif" height="12" width="11" border="0" style="margin-left:45px" /></div>
   <div class="SelEm">
    <div class="emlist">
       <ul>
		<?php foreach($expression as $k=>$v){?>
        <li><img src="<?=$navheadurl?>images/emoticons/<?=$k?>.gif" style="cursor:pointer" onclick="addExpression('comment','{<?=$v?>}');"/></li>
		<?php }?>
      </ul>
    </div>
    <a onclick="$('#expression1').fadeOut('slow');"><div class="emclose"></div></a>
   </div>
  </div>
</div>
<script type="text/javascript">
//OnClick(1);
shsend(1);
</script>

<div class="lineclear" style="margin-top:50px"></div>
<?php
include("../template/".MOBAN."/footer.tpl.php");
?>
</body>
</html>
